/*

* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Smart-Shop开源商城系统/ Java商城-首选电商平台系统 请务必保留此注释头信息
* |     开源地址: https://gitee.com/ningbo-qishan/gruul-mall
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     可正常分享和学习源码,未经授权 不可商用！
* |     商业版中台购买/开源版商业授权 联系技术客服
* |     官网:  https://www.73app.cn/
* ------------------------------------------------------------------------
* ------------------------------------------------------------------------
* |     Copyright (c) 2016-2999 宁波启山智软科技有限公司
* |     版权所有 ,侵权必究！
* ------------------------------------------------------------------------

*/
package com.medusa.gruul.payment.conf;

import com.egzosn.pay.spring.boot.core.PayServiceConfigurer;
import com.egzosn.pay.spring.boot.core.configurers.MerchantDetailsServiceConfigurer;
import com.egzosn.pay.spring.boot.core.configurers.PayMessageConfigurer;
import com.egzosn.pay.spring.boot.core.merchant.PaymentPlatform;
import com.egzosn.pay.spring.boot.core.provider.merchant.platform.AliPaymentPlatform;
import com.egzosn.pay.spring.boot.core.provider.merchant.platform.PaymentPlatforms;
import com.egzosn.pay.spring.boot.core.provider.merchant.platform.WxPaymentPlatform;
import com.egzosn.pay.spring.boot.core.provider.merchant.platform.WxV3PaymentPlatform;
import com.medusa.gruul.payment.handler.notify.AliPayMessageHandler;
import com.medusa.gruul.payment.handler.notify.WxPayMessageHandler;
import com.medusa.gruul.payment.interceptor.AliPayMessageInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * @author 张治保
 * date 2021/12/15
 */
@Configuration
@RequiredArgsConstructor
public class MerchantPayServiceConfig implements PayServiceConfigurer {

    private final AliPayMessageHandler aliPayMessageHandler;
    private final AliPayMessageInterceptor aliPayMessageInterceptor;
    private final WxPayMessageHandler wxPayMessageHandler;
    private final JdbcTemplate jdbcTemplate;
    /**
     * 商户配置
     * @param merchants 商户配置
     */
    @Override
    public void configure(MerchantDetailsServiceConfigurer merchants)  {
        merchants.jdbc()
            .cache(false)
            .template(jdbcTemplate);
    }
    /**
     * 商户配置
     *
     * @param configurer 支付消息配置
     */
    @Override
    public void configure(PayMessageConfigurer configurer) {

        PaymentPlatform aliPaymentPlatform = PaymentPlatforms.getPaymentPlatform(AliPaymentPlatform.platformName);
        configurer.addHandler(aliPaymentPlatform, aliPayMessageHandler);
        configurer.addInterceptor(aliPaymentPlatform, aliPayMessageInterceptor);

        PaymentPlatform wechatPaymentPlatform = PaymentPlatforms.getPaymentPlatform(WxPaymentPlatform.platformName);
        configurer.addHandler(wechatPaymentPlatform, wxPayMessageHandler);

        PaymentPlatform wxV3PaymentPlatform = PaymentPlatforms.getPaymentPlatform(WxV3PaymentPlatform.platformName);
        configurer.addHandler(wxV3PaymentPlatform, wxPayMessageHandler);
    }
}
